package com.mayblackcat.dy.dao;

import com.mayblackcat.dy.entity.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentDao {

    @Insert("insert into t_comment(id,nickName,content,avatar,likes,createTime,parentCommentId,videoId) " +
            "values(#{id},#{nickName},#{content},#{avatar},#{likes},#{createTime},#{parentCommentId},#{videoId})")
        //添加一个评论
    int saveComment(Comment comment);

    @Select("select * from t_comment where parentCommentId = #{parentCommentId} order by createTime desc")
        //查询父级评论
    List<Comment> findByParentIdNull(@Param("parentCommentId") Long ParentId);

    //查询一级回复
    @Select(" select * from t_comment  where parentCommentId = #{id}  order by createTime desc")
    List<Comment> findByParentIdNotNull(@Param("id") Long id);

    //查询二级以及所有子集回复
    @Select("select *  from t_comment where parentCommentId = #{sonCommentId} order by createTime desc")
    List<Comment> findByReplayId(@Param("sonMessageId") Long childId);

    //删除评论
    @Delete("delete from t_comment where id = #{id}")
    void deleteComment(Long id);
}
